package structure.Proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by LYJ on 2016/10/19.
 * 动态代理
 */
public class ProxyHandler implements InvocationHandler{
    Object object=null;
    public Object newProxyInstance(Object realObject){
        this.object=realObject;
        Class<?> classType= this.object.getClass();
        return Proxy.newProxyInstance(classType.getClassLoader(),classType.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("I'm proxy, I'm invoking...");
        method.invoke(object,args);
        System.out.println("invoke end!");
        return null;
    }
}
